/*
 * Syncrem - Tool for remote synchronizing
 *
 * Copyright (c) 2011 Norbert Chromek <norbert.chromek@gmail.com>
 *
 * Syncrem is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Syncrem is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Syncrem. If not, see <http://www.gnu.org/licenses/>.
 */


#include "signalhandler.h"

// initialiaze static members
SignalHandler::Signals SignalHandler::signals_;

/**
 * Constructor
 */

SignalHandler::SignalHandler() {

	registerSignals();
}

/**
 * Destructor.
 */

SignalHandler::~SignalHandler() {

}

/**
 * This function adds signal to queue.
 * Should not be called directly.
 * 
 * @param signal Signal to be added.
 */

void SignalHandler::addSignal(int signal) {
	signals_.push(static_cast<AcceptedSignals>(signal));
}

/**
 * Checks whether there are any signals
 * in queue.
 * 
 * @return True if there are any signals caught.
 */

bool SignalHandler::hasSignal() {
	return !signals_.empty();
}

/**
 * This function returns number of signal in queue.
 * 
 * @return Number of signal.
 */

SignalHandler::AcceptedSignals SignalHandler::nextSignal() {
	return signals_.front();
}

/**
 * This function assigns signals to their handlers.
 */

void SignalHandler::registerSignals() {
	signal(SIGTERM, SignalHandler::addSignal);
}